package com.shiwenping.reply.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.CompoundButton;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.jakewharton.rxbinding2.view.RxView;
import com.shiwenping.reply.App;
import com.shiwenping.reply.R;
import com.shiwenping.reply.databinding.FragmentSettingBinding;
import com.shiwenping.reply.tools.Path;
import com.shiwenping.reply.tools.sp.SharedPreferenceUtil;

/**
 * @author shiwenping
 * @date 17-11-7 下午5:41
 */

@Route(path = Path.MAIN_SETTING)
public class SettingFragment extends BaseFragment<FragmentSettingBinding> {
    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        databinding.isShowToast.setChecked(SharedPreferenceUtil.get(getContext(), Path.KEY_IS_TOAST, true));
        databinding.isShowToast.setOnCheckedChangeListener((compoundButton, b) -> {
            SharedPreferenceUtil.put(getContext(), Path.KEY_IS_TOAST, b);
            databinding.isShowToastLeft.setEnabled(b);
        });

        databinding.isShowToastLeft.setChecked(SharedPreferenceUtil.get(getContext(), Path.KEY_IS_TOAST_LEFT, true));

        databinding.isShowToastLeft.setOnCheckedChangeListener((compoundButton, b) -> {
            SharedPreferenceUtil.put(getContext(), Path.KEY_IS_TOAST_LEFT, b);
        });

        RxView.clicks(databinding.exit)
                .subscribe(o -> App.exitToLoginActivity());
    }

    @Override
    int resLayout() {
        return R.layout.fragment_setting;
    }
}
